const express = require('express');
const path = require('path');
const os = require('os');

const app = express();
const PORT = 3000;

// 设置静态文件目录
app.use(express.static(path.join(__dirname, 'web')));

// 默认路由指向demo.html
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'web', 'demo.html'));
});

// 获取本机IP地址
function getLocalIP() {
    const networkInterfaces = os.networkInterfaces();
    for (const interfaceName in networkInterfaces) {
        const addresses = networkInterfaces[interfaceName];
        for (const address of addresses) {
            if (address.family === 'IPv4' && !address.internal) {
                return address.address;
            }
        }
    }
    return 'localhost';
}

app.listen(PORT, '0.0.0.0', () => {
    const localIP = getLocalIP();
    console.log('🚀 粒子动画演示服务器已启动!');
    console.log(`📱 本地访问: http://localhost:${PORT}`);
    console.log(`🌐 网络访问: http://${localIP}:${PORT}`);
    console.log('\n可用的演示页面:');
    console.log(`  • 打开该死fuck网页: http://${localIP}:${PORT}/two_anniversary_celebration.html`);
});

// 优雅关闭处理
process.on('SIGINT', () => {
    console.log('\n👋 服务器正在关闭...');
    process.exit(0);
}); 